package com.kaifamiao.thread.d0928.pm;

import java.net.*;

public class GroupServer {

    public static void main(String[] args) throws Exception {
        MulticastSocket socket = new MulticastSocket();

        // 加入到 组中
        InetAddress address = InetAddress.getByName("224.0.1.0");
        System.out.println(address);
        socket.joinGroup(new InetSocketAddress(address,8888), NetworkInterface.getByInetAddress(address));
//        socket.joinGroup(InetAddress.getByName("224.0.1.0"));

        byte[] bytes = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length);

        socket.receive(packet); // 接收信息

        int length = packet.getLength();

        System.out.println(new String(packet.getData(), 0, length));

//        System.out.println(new String(bytes, 0, length));

    }
}
